	package charts.elements ;
	import charts.elements.PointDotBase;
	import flash.display.BlendMode;
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	class Star extends PointDotBase {
		
		public function new ( index: Int, style: Dynamic ) {
			
			super( index, style );
			
			this.visible = true;
			
			this.graphics.clear();
			this.graphics.lineStyle( style.width, style.color, 1);// style.alpha );
			var rotation: Float = 0

			if ( Reflect.hasField(style, rotation)
				&& Math.isNaN(Reflect.field(style,rotation)) )
				rotation = style.rotation;
			
			this.drawStar( this.graphics, style.dot_size, rotation );
			
			var haloSize : Float = style.halo_size + style.dot_size;
			var s:Sprite = new Sprite();
			s.graphics.lineStyle( 0, 0, 0 );
			s.graphics.beginFill( 0, 1 );
			this.drawStar(s.graphics, haloSize, rotation );
			s.blendMode = BlendMode.ERASE;
			s.graphics.endFill();
			this.line_mask = s;
			
			this.attach_events();
			
		}
		
		function calcXOnCircle (radius: Float, degrees: Float): Float
		{
			return radius * Math.cos(degrees / 180 * Math.PI);
		}
		
		function calcYOnCircle (radius: Float, degrees: Float): Float
		{
			return radius * Math.sin(degrees / 180 * Math.PI);
		}
		
		function drawStar ( graphics:Graphics, radius: Float, rotation: Float ): Void 
		{
			var angle: Float = 360 / 5;

			// Start at top point (unrotated)
			var degrees: Float = -90 + rotation;
			for ( i in 0...6 )
			{
				var x: Float = this.calcXOnCircle(radius, degrees);
				var y: Float = this.calcYOnCircle(radius, degrees);
				
				if (i == 0)
					graphics.moveTo(x, y);
				else
					graphics.lineTo(x, y);
					
				// Move 2 points clockwise
				degrees += (2 * angle);
			}
		}
	}

